package com.kingtone.rongji;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.kingtone.rongji.biz.User;
import com.kingtone.rongji.network.UserRequest;
import com.kingtone.rongji.ui.ToastManager;

public class PasswordStep1Activity extends BaseActivity {

	private static final String TAG = "PasswordStep1Activity";

	private Activity mContext;
	
	private Button mNextBtn;

	private EditText mUserName;

	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		this.mContext = this;
		this.setContentView(R.layout.activity_find_pwd_step1);
		setupView();
	}

	private void setupView() {
		
		initTitleView(getString(R.string.title_find_pwd));
		
		mUserName = (EditText) this.findViewById(R.id.id_et_username);

		mNextBtn = (Button) this.findViewById(R.id.id_bt_next);
		mNextBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String account = mUserName.getText().toString();
				if (account.equals("")) {
					ToastManager.show(mContext, getResources().getString(
							R.string.login_username_empty_label));
					return;
				}
				
				UserRequest userRequest = new UserRequest();
				userRequest.getUserInfoByName(account, PasswordStep1Activity.this);
			}
		});
	}
	
	@Override
	public void onBussinessSuccess(Object obj) {
		// TODO Auto-generated method stub
		super.onBussinessSuccess(obj);
		if(obj instanceof User)
		{
			User user = (User) obj;
			if(user.getUserId() > 0)
			{
				Intent intent = new Intent(PasswordStep1Activity.this, PasswordStep2Activity.class);
				intent.putExtra("Email", user.getEmail());
				intent.putExtra("CellPhone", user.getCellPhone());
				intent.putExtra("UserName", user.getUserName());
				intent.putExtra("UserId", user.getUserId());
				startActivity(intent);
				return;
			}
			
			ToastManager.show(mContext, mContext.getResources().getString(R.string.error_user_not_exist));
		}
	}
}
